package com.lzc.product.service;

import com.lzc.product.service.ProductService;
import com.lzc.product.dao.ProductDao;
import com.lzc.product.model.Product;
import com.lzc.product.model.ShoppingCar;


import java.util.List;

public class ProductService {
    /** 获取商品列表*/
    public List<Product> getProductList(){
        ProductDao dao = new ProductDao();
        List<Product> list = dao.getProductList();
        return list;
    }

    public Product getProductById(String id) {
        ProductDao dao = new ProductDao();
        Product product = dao.getProductById(id);
        return product;
    }

    //        将商品信息添加到购物车
    public boolean addCar(String customerId,String productId ,String number) {
        ProductDao dao = new ProductDao();
        int num = dao.isExists(customerId,productId);
        int result=0;
        if(num>0){
            result=dao.updateCar(customerId,productId,String.valueOf(num+1));
        }else {
            result= dao.addCar(customerId,productId,number);
        }
        return result == 1;
    }

    /**根据用户编号查询该会员的购物车信息*/
    public List<ShoppingCar> getShoppingCarInfo (String customerId) {
        ProductDao dao = new ProductDao();
        List<ShoppingCar> list=dao.getShoppingCarInfo(customerId);
        return list;
    }
    /** 根据会员联系方式来生成订单*/
    public boolean addOrder(String phone,String price , List<ShoppingCar>list){
        ProductDao dao = new ProductDao();
        int num =dao.addOrder(phone,price,list);
        return num > 0;
    }
}
